<template>
  <div class="home">
    <Header />
    <Swiper :swiperList='swiperList' />
    <Icon :iconList='iconList' />
    <Recommend :recommendList='recommendList' />
    <Weekend :weekendList='weekendList' />
  </div>
</template>

<script>
import axios from 'axios'
import { mapState } from 'vuex'
import Header from '@/components/Header'
import Swiper from '@/components/Swiper'
import Icon from '@/views/home/children/Icons'
import Recommend from './children/Recommend.vue'
import Weekend from './children/Weekend.vue'
export default {
  name: 'Home',
  components: {
    Header,
    Swiper,
    Icon,
    Recommend,
    Weekend
  },
  data () {
    return {
      lastCity: '',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  },
  methods: {
    getHomeInfo () {
      axios.get(`http://localhost:8080/mock/index.json?city=${this.city}`).then(res => {
        res = res.data
        if (res.ret && res.data) {
          const data = res.data
          this.swiperList = data.swiperList
          this.iconList = data.iconList
          this.recommendList = data.recommendList
          this.weekendList = data.weekendList
        }
      })
    }
  },
  computed: {
    ...mapState(['city'])
  }
}
</script>

<style lang="less" scoped>

</style>
